package api.base.impl;

import android.database.Observable;

import java.lang.reflect.ParameterizedType;

import api.factioy.RetrofitFactory;
import api.utils.DataCache;
import api.utils.Utils;

/**
 * Created by Administrator on 2018-01-12.
 */

public class BaseImpl<Service> implements IGetService<Service> {
    protected DataCache mDataCache;
    protected Retrofit mRetrofit;
    protected  Service mService;

    public BaseImpl(){
        System.out.println("    "+ Utils.getContext().toString());
        mDataCache = DataCache.getInstance();
        mRetrofit = RetrofitFactory.getRetrofit();
       this.mService =mRetrofit.create(getServiceClass());
    }
    /** 线程调度封装 */
    protected <T> Observable<T> scheduler(Observable<T> observable){
        return observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }


    @Override
    public Class<Service> getServiceClass() {
        return (Class<Service>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }
}
